<?php
include dirname(dirname(__FILE__)).'/admin-verify.php';
include dirname(__FILE__).'/functions.php';
?>
<!DOCTYPE html>
<html>
<head>
		<?php include dirname(dirname(dirname(__FILE__))).'/include/common-header.php' ?>
		<script type="text/javascript">
		$(document).ready(function (){
			var _y = <?php echo date('Y'); ?>;
			var _m = <?php echo date('m'); ?>;
			if(_m<10)_m="0"+_m;
			$("#year option[value='"+_y+"']").attr("selected","selected");
			$("#month option[value='"+_m+"']").attr("selected","selected");
			$.ajax({
				dataType:"json",
				url:'ajax/get-user-worktime.php',
				data:{year:_y,month:_m},
				success:function(data) {
					if(data!='no') {
						var objs = eval(data);
						for(var i=0;i<objs.length;i++) {
							$("#"+objs[i].id).html(objs[i].wt);
						}
					} 
				},
			});
			$("select").change(function() {
				var _year = $("#year option:selected").val();
				var _month = $("#month option:selected").val();
				$.ajax({
					dataType:"text",
					url:'ajax/get-user-worktime.php',
					data:{year:_year,month:_month},
					success:function(data) {
						if(data!='no') {
							var objs = eval(data);
							for(var i=0;i<objs.length;i++) {
								$("#"+objs[i].id).html(objs[i].wt);
							}
						} 
					},
				});
			});
		});</script>
		<link rel="stylesheet" type="text/css" href="../css/style.css">
</head>
<body>
	
	<div class="col-md-12">
		<div>
			<h3>查看员工工时</h3>
		</div>
		<div>
			<form id="submit-form" class="form-inline" role="form">			
				</select>
				选择查询年份<select class="form-control" id="year" name="year" style="margin-left:10px;margin-right:10px;">
					<?php 
						$st = 2014;$end = date('Y');
						for($i=$st;$i<=$end;$i++) {
							echo '<option value="'.$i.'">'.$i.'</option>';
						}
					?>
				</select>
				月份<select class="form-control" id="month" name="month" style="margin-left:10px;">
					<?php 
						for($i=1;$i<=9;$i++) {
							echo '<option value="0'.$i.'">'.$i.'</option>'; 
						}
						for($i=10;$i<=12;$i++) {
							echo '<option value="'.$i.'">'.$i.'</option>'; 	
						}
					?>
				</select>
				<table class="table table-striped table-bordered table-hover table-condensed default-table" 
					style="margin-top:20px;width:60%" id="default-table">
					<tr>
						<th>用户名</th>
						<th>姓名</th>
						<th>工时</th>
					</tr>
					<?php 
						$items = getAllUser();
						foreach($items as $user) {
							echo '<tr>';
							echo '<td>'.$user['username'].'</td>';
							echo '<td>'.$user["user_real_name"].'</td>';
							echo '<td id="'.$user['id'].'"></td>';
							echo '</tr>';
						}
					?>
				</table>
			</form>
			<h3 id="work-time" style="margin-top:40px;"></h3>
		</div>
	</div>
</body>